function [Q, LL] = mog_E_step(X, mog)
% implements the E-step of the algorithm. The parameters are X,
% the data, and MOG the current parameter values. The function does not change the parameters but
% computes Q, a matrix that contains the probability of each mixture component given the data p(z|x, θ),
% and LL, the log-likelihood of the data set under the mixture model.
%
% 2012 Maarten Inja & Chiel Kooijman.

s = size(mog, 2);

Q = zeros(size(X, 1), s);

for i = 1:s
    mv = mvnpdf(X, mog{i}.MU, mog{i}.SIGMA);
    Q(:, i) = mog{i}.PI*mv;
end

LL = sum(sum(log(Q), 2));

Q ./= repmat(sum(Q, 2), 1, s);
